/*
 * Copyright (C), 2014-2014, 联创车盟汽车服务有限公司
 * FileName: MyScrollView.java
 * Author:   zbhcit
 * Date:     2014-12-18 下午9:37:34
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.fuyunxing.pad.framework.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;

/**
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author zbhcit
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class MyScrollView extends ScrollView {
    private boolean canScroll;
   
    private GestureDetector mGestureDetector;
    View.OnTouchListener mGestureListener;
   
    public MyScrollView(Context context, AttributeSet attrs) {
      super(context, attrs);
      mGestureDetector = new GestureDetector(new YScrollDetector());
      canScroll = true;
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
      if(ev.getAction() == MotionEvent.ACTION_UP)
        canScroll = true;
      return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
    }
   
    class YScrollDetector extends SimpleOnGestureListener {
      @Override
      public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        if(canScroll)
          if (Math.abs(distanceY) >= Math.abs(distanceX))
            canScroll = true;
          else
            canScroll = false;
        return canScroll;
      }
    }
  }